/*
package com.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;

*/
/**
 * 作者: LCG
 * 日期: 2019/8/8 17:14
 * 描述: 重新构建请求，该操作代码是完成请求重建的功能，
 * 将https的请求变为http的请求，方便将网关变为https的时候
 * 后台服务的所有请求依然为 http访问
 *//*

@Component
public class HttpsGlobalFilter implements GlobalFilter,Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        URI uri = exchange.getRequest().getURI();
        ServerHttpRequest request = exchange.getRequest();
        ServerHttpRequest.Builder mutate = request.mutate();

        if(uri.toString().startsWith("http")){
             try{
                 String userInfo = uri.getUserInfo();
                 URI uri1 = new URI(
                         "http",
                         userInfo,
                         uri.getHost(),
                         uri.getPort(),
                         uri.getPath(),
                         uri.getQuery(),
                         uri.getFragment()
                 );
                 mutate.uri(uri1);
             }catch (Exception e){
                 throw new IllegalStateException(e.getMessage(),e);
             }
        }
        ServerHttpRequest build = mutate.build();

        return chain.filter(exchange.mutate().request(build).build());
    }

    @Override
    public int getOrder() {
        return 10001;
    }
}
*/
